package com.company.utils;

import com.company.entity.User;
import org.junit.Test;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class MyFileUtil {

    @Test
    public void testSerizi(){
        List<User> users = new ArrayList<User>();
        users.add(new User("admin","123"));
        users.add(new User("root","456"));
        users.add(new User("ry","ry"));

        try {
            FileOutputStream outputStream = new FileOutputStream("D:\\demo\\1.bat");
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
            objectOutputStream.writeObject(users);

            FileInputStream fileInputStream = new FileInputStream("D:\\demo\\1.bat");
            ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
            List<User> userlist = (List<User>)objectInputStream.readObject();
            System.out.println();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
        }
    }
}